# encoding: utf-8

require 'rubygems'
require 'test/unit'
require 'test/unit/testsuite'
require 'test/unit/ui/console/testrunner'

$suite_names = []

LOAD_PATH = File.dirname(__FILE__)

Dir.glob(LOAD_PATH + '/**/test_*.rb').each do |file_path|
  require file_path
  prefix      = file_path.split('/')[1..-2].join('/')
  prefix      = prefix + '/' unless prefix == ''
  filename    = file_path.split('/').last
  words       = filename.split('.')[0].split('_')
  testcase_id = ''
  words.each_with_index do |word, index|
    e_word = "#{word.capitalize}"
    if word == 'caiqiu'
      e_word = 'CaiQiu'
    end
    if index == 0
      testcase_id = "#{e_word}"
    else
      testcase_id = "#{testcase_id}_#{e_word}"
    end
  end
  puts "add case #{prefix}#{testcase_id}"
  $suite_names << testcase_id
end

class CapevaluationTests
  def self.suite
    suites = Test::Unit::TestSuite.new('CapevaluationTests')
    $suite_names.each do |suite_name|
      suites << eval("#{suite_name}.suite")
    end
    suites
  end
end

result = Test::Unit::UI::Console::TestRunner.run(CapevaluationTests)

print_msg =
        "断言数量: #{result.assertion_count}\n" +
        "测试数量: #{result.run_count}\n" +
        "错误数量: #{result.error_count}\n" +
        "失败数量: #{result.failure_count}"

puts print_msg